<!--
* description: 外采供应商查询
* author: xiaochengzuan
* createdDate: 2021-3-2
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
      :callback-obj="callbackObj"
    />

    <!-- <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    /> -->
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import Vue from "vue";

import { orgApis } from '@/api/pabasicdataapi'
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: "outsourcingSupplierQuery",

  components: {
    OneTableTemplate,
    // Edit: () => import("./edit"),
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      icon: "el-icon-arrow-down",
      status: false,
      editRowData: {},
      selectiondata: null,
      // 网格查询API配置对象
      apiConfig: orgApis.outsourcingsupplierqueryquery,
      columnStyle({ row, column, rowIndex, columnIndex }) {
        if (
          (columnIndex === 8 && parseFloat(row.profitQuarters) <= 30) ||
          (columnIndex === 12 && parseFloat(row.outletsQuarters) < 25)
        ) {
          return "background:red";
        } else if (
          (columnIndex === 8 && parseFloat(row.profitQuarters) > 35) ||
          (columnIndex === 12 && parseFloat(row.outletsQuarters) > 30)
        ) {
          return "background:yellow";
        }
      },
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
          {
          compKey: "btnKey3",
          type: "",
          size: "small",
          clickEvent: () => this.exportExcel1(),
          text: "导出",
          name: "export",
          position: "right",
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
      
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
            //   {
            //     compKey: "compKey1",
            //     labelName: "维修类型：",
            //     codeField: "maintenanceType",
            //     component: () => import("@/components/org/LookupValue"),
            //     oFields: "statusId,statusText",
            //     options: [
            //       { statusId: "0", statusText: "保养件" },
            //       { statusId: "1", statusText: "易损件" },
            //       { statusId: "2", statusText: "事故件" },
            //       { statusId: "3", statusText: "轮胎" },
            //       { statusId: "4", statusText: "精品" },
            //     ],
            //     type: "dropdownList",
            //     isMul: false,
            //     isMust: true,
            //   },
              {
                compKey: "compKey2",
                labelName: "网点编码：",
                codeField: "dlrCode", 
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },         
              {
                compKey: "compKey3",
                labelName: "供应商编码：",
                codeField: "supplierCode", 
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
               {
                compKey: "compKey10",
                labelName: "供应商简称：",
                codeField: "supplierShortName", 
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey4",
                labelName: "状态: ",
                codeField: "isEnable", 
                component: () => import("@/components/org/LookupValue"),
                oFields: "statusId,statusText",
                options: [
                  { statusId: "1", statusText: "启动" },
                  { statusId: "0", statusText: "停用" },
                ],
                type: "dropdownList",
                isMul: false,
                isMust: true,
              },
              //        {
              //   compKey: "compKey5",
              //   labelName: "采购开关: ",
              //   codeField: "status1",
              //   component: () => import("@/components/org/LookupValue"),
              //   oFields: "statusId,statusText",
              //   options: [
              //     { statusId: "1", statusText: "厂家备件" },
              //     { statusId: "0", statusText: "网点备件" },
              //   ],
              //   type: "dropdownList",
              //   isMul: false,
              //   isMust: false,
              // },

              //      {
              //   compKey: "compKey6",
              //   labelName: "销售开关: ",
              //   codeField: "status2",
              //   component: () => import("@/components/org/LookupValue"),
              //   oFields: "statusId,statusText",
              //   options: [
              //     { statusId: "1", statusText: "厂家备件" },
              //     { statusId: "0", statusText: "网点备件" },
              //   ],
              //   type: "dropdownList",
              //   isMul: false,
              //   isMust: false,
              // },

              //   {
              //   compKey: "compKey10",
              //   labelName: "订货开关: ",
              //   codeField: "status5",
              //   component: () => import("@/components/org/LookupValue"),
              //   oFields: "statusId,statusText",
              //   options: [
              //     { statusId: "1", statusText: "厂家备件" },
              //     { statusId: "0", statusText: "网点备件" },
              //   ],
              //   type: "dropdownList",
              //   isMul: false,
              //   isMust: false,
              // },

              //      {
              //   compKey: "compKey7",
              //   labelName: "供应商: ",
              //   codeField: "status3",
              //     component: () => import('@/components/ve/carStockHouse'),
              //   oFields: "statusId,statusText",
              //   options: [
              //     { statusId: "1", statusText: "厂家备件" },
              //     { statusId: "0", statusText: "网点备件" },
              //   ],
              //   type: "dropdownList",
              //   isMul: false,
              //   isMust: false,
              // },

              //       {
              //   compKey: "compKey8",
              //   labelName: "适用车型: ",
              //   codeField: "status4",
              //     component: () => import('@/components/ve/carStockHouse'),
              //   oFields: "statusId,statusText",
              //   options: [
              //     { statusId: "1", statusText: "厂家备件" },
              //     { statusId: "0", statusText: "网点备件" },
              //   ],
              //   type: "dropdownList",
              //   isMul: false,
              //   isMust: false,
              // },


              //      {
              //   compKey: "compKey9",
              //   labelName: "备件编码：",
              //   codeField: "partNameCode4",
              //   component: () => import("@/components/org/commonInput"),
              //   type: "inputText",
              //   isMul: false,
              //   isMust: false,
              //   span:12
              // },
            ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "releaseId",
                label: "主键ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "dlrCode",
                label: "网点编码",
              
              },
              {
                prop: "dlrShortName",
                label: "网点名称",
              },
              {
                prop: "supplierCode", 
                label: "供应商编码",
              },

              {
                prop: "supplierShortName",
                label: "供应商简称",
              },
              {
                prop: "supplierFullName", 
                label: "供应商全称",
              },
              {
                prop: "supplierAddr", 
                label: "详细地址",
              },
              {
                prop: "linkManTel", 
                label: "联系电话",
              },
              {
                prop: "isEnableCn", 
                label: "状态",
              },
                {
                prop: "remark",
                label: "备注",
              },
         
              

             
              

           

              

          
              
            

            

             
            ],
      callbackObj: {
        // 手动勾选时
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection;
        },
        onCheckSelectChange: (selection) => {
          this.onCheckSelectChange1(selection);
        },
      },
      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {
          dlrCode:'',
          supplierCode:'', 
          supplierShortName:'', 
          isEnable:'', 




         
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },
  watch: {
    "formField.orderStatus": {
      deep: true,
      handler: function (newV, oldV) {
        console.log("watch中：", newV);
        // this.querybystatus(newV)
        this.queryTable();
      },
    },
  },
  mounted() {
    // 列表查询
    // this.queryTable(1)
    this.$refs["multipleTable"].list = [
      {
        releaseId: "1",
        updateControlId: "1",
        profitQuarters: "42.86%",
        outletsQuarters: "30%",
      },
      {
        releaseId: "2",
        updateControlId: "2",
        profitQuarters: "18.92%",
        outletsQuarters: "7.5%",
      },
      {
        releaseId: "3",
        updateControlId: "3",
        profitQuarters: "32%",
        outletsQuarters: "28%",
      },
    ];
  },

  methods: {
    // 订单状态切换
    togglestatus() {
      if (this.status === true) {
        this.icon = "el-icon-arrow-down";
        this.status = false;
      } else {
        this.icon = "el-icon-arrow-up";
        this.status = true;
      }
      this.$refs.multipleTable.$refs.compKey11[0].curIsShow = this.status;
      this.$refs.multipleTable.setTableHeight();
    },
    onCheckSelectChange1(selection) {
      var btn1 = this.tableButtons[2];
      var btn2 = this.tableButtons[3];
      const isCheck = selection && selection.length > 0;
      btn1.disabled = !isCheck;
      btn2.disabled = !isCheck;
    },
    // 批量驳回、通过
    pass(type) {
      if (type === '0') {
        debugger
        this.editPopupsState = "edit";
        this.editPopupsVisible = true;
        // this.editRowData = this.$utils.deepCopy(
        //   this.$refs["multipleTable"].list[index]
        // );
      }
    },


    exportExcel1(){
      //导出
      // outsourcingsupplierqueryexportexcel

       exportExcel(this.formField, orgApis.outsourcingsupplierqueryexportexcel.APIUrl, orgApis.outsourcingsupplierqueryexportexcel.ServiceCode, '外采供应商查询')

    }
  },
};
</script>
<style lang='scss' scoped>
.red {
  background: red;
}
</style>